package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.OmsOrderReturnApply;
import com.itheima.mapper.OmsOrderReturnApplyMapper;
import com.itheima.service.OmsOrderReturnApplyService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单退货申请 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class OmsOrderReturnApplyServiceImpl extends ServiceImpl<OmsOrderReturnApplyMapper, OmsOrderReturnApply> implements OmsOrderReturnApplyService {

    @Autowired
    OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;

    @Override
    public PageBeanVo findByPage(String createTime, String handleMan, String handleTime, Integer id,
                                 Integer pageNum, Integer pageSize, String receiverKeyword, Integer status) {

        Page<OmsOrderReturnApply> page = new Page<>(pageNum,pageSize);

        //条件查询
        LambdaQueryWrapper<OmsOrderReturnApply> qw = new LambdaQueryWrapper<>();

        qw.like(handleMan!=null,OmsOrderReturnApply::getHandleMan,handleMan);
        qw.eq(createTime!=null,OmsOrderReturnApply::getCreateTime,createTime);
        qw.eq(handleTime!=null,OmsOrderReturnApply::getHandleTime,handleTime);
        qw.eq(id!=null,OmsOrderReturnApply::getId,id);
        qw.eq(status!=null,OmsOrderReturnApply::getStatus,status);
        qw.orderByDesc(OmsOrderReturnApply::getCreateTime);

        Page<OmsOrderReturnApply> omsOrderPage = omsOrderReturnApplyMapper.selectPage(page,qw);

        return new PageBeanVo(pageNum,pageSize,omsOrderPage.getTotal(),omsOrderPage.getRecords());
    }

    //获取退货申请详情
    @Override
    public OmsOrderReturnApply findById(Long id) {
        return omsOrderReturnApplyMapper.selectById(id);
    }

    //修改退货申请状态
    @Override
    public void updateStatus(OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApplyMapper.updateById(omsOrderReturnApply);
    }

    //批量删除退货申请
    @Override
    public void delete(List<Long> ids) {
        omsOrderReturnApplyMapper.deleteBatchIds(ids);
    }
}
